<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>高精度算法 | Hugo Theme Dream</title>

    



<meta name="author" content="Lindixuan" />
<meta name="description" content="" />



<meta name="generator" content="Hugo 0.63.2" />

<link rel="canonical" href="https://lindixuan.gitee.io/post/%E9%AB%98%E7%B2%BE%E5%BA%A6%E7%AE%97%E6%B3%95/" />


<meta property="og:title" content="高精度算法" />
<meta property="og:description" content="" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://lindixuan.gitee.io/post/%E9%AB%98%E7%B2%BE%E5%BA%A6%E7%AE%97%E6%B3%95/" />
<meta property="article:published_time" content="2020-09-07T23:59:17+08:00" />
<meta property="article:modified_time" content="2020-09-07T23:59:17+08:00" />



<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="高精度算法"/>
<meta name="twitter:description" content=""/>


<link rel="stylesheet" href="/css/semantic.min.css" />
<link rel="stylesheet" href="/css/OverlayScrollbars.min.css" />
<link rel="stylesheet" href="/css/github-markdown.css" />
<link rel="stylesheet" href="/css/site.css" />


<style>
  a {
    color: seagreen !important;
  }
</style>



<style>
  .inverted a {
     color: darkseagreen !important;
  }
</style>


    


  
    <link rel="stylesheet" data-highlight href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/styles/gruvbox-light.min.css" />
  



  </head>

  
  <body style="background: white;">
  
    
<nav class="ui secondary inverted menu dream-menu">

  <div class="item">
    <i class="large link bullseye icon dream-flip-toggle" title="Flip it!"></i>
  </div>
  <div class="item">
    <i class="large link home icon" title="Home" onclick="window.location.href = 'https:\/\/lindixuan.gitee.io'"></i>
  </div>
  <div class="item">
    <i class="large link icon theme-switch" onclick="themeSwitch()"></i>
  </div>
  
  <div class="item">
    <i class="large link search icon" onclick="toggleSearch()"></i>
  </div>
  
</nav>

    <div class="flip-container">
      <div class="flipper">
        <section class="front">
          <div class="dream-max-width">
            
<div class="ui centered relaxed grid dream-grid">
  <div class="sixteen wide mobile sixteen wide tablet twelve wide computer column markdown-body dream-single">

    <section class="ui top attached segment" id="dream-save-post-as-img">
      <header style="margin-top: 0 !important;">
        <h1 class="ui large header">
          高精度算法
          <div class="sub header">
            @
            
              Lindixuan
            
            · Monday, Sep 7, 2020
            · 3 minute read
            · Update at Sep 7, 2020
          </div>
        </h1>
      </header>

      
        <img class="ui image" style="margin-top: 2rem;" src="" />
      

      <article style="margin-top: 2rem;"><h1 id="高精度算法">高精度算法</h1>
<p>在日常生活中，我们经常需要编写程序来解决问题，其中涉及数字运算。众所周知，unsigned long long 类型最大也只能取值1844674407370955161，当我们要对更大的数字进行运算时，可采用高精度计算方法。</p>
<h2 id="高精度加法">高精度加法</h2>
<blockquote>
<p>用字符串 str1 和 str2 来储存需要运算的两个数字，然后创建两个整数数组将字符串转化成数字。在字符串中数字是左对齐的，而我们进行加法时需要数字从最小位对齐，所以我们将字符串中最后一位数字存在数组第一位，以此类推将数字在数组中反向存放。<br>
计算时只需要一位一位加即可，满十进位，最后去除最高位的零。</p>
</blockquote>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp"><span style="color:#75715e">#</span><span style="color:#75715e">include</span><span style="color:#75715e">&lt;iostream&gt;  </span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#75715e">#</span><span style="color:#75715e">include</span><span style="color:#75715e">&lt;cstring&gt;  </span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;  
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>()  
{  
  string str1,str2;  
  <span style="color:#66d9ef">int</span> a[<span style="color:#ae81ff">250</span>],b[<span style="color:#ae81ff">250</span>],len;   <span style="color:#75715e">//数组的大小决定了计算的高精度最大位数  
</span><span style="color:#75715e"></span>  <span style="color:#66d9ef">int</span> i;  
  memset(a,<span style="color:#ae81ff">0</span>,<span style="color:#66d9ef">sizeof</span>(a));  
  memset(b,<span style="color:#ae81ff">0</span>,<span style="color:#66d9ef">sizeof</span>(b));  
  cin<span style="color:#f92672">&gt;</span><span style="color:#f92672">&gt;</span>str1<span style="color:#f92672">&gt;</span><span style="color:#f92672">&gt;</span>str2;   <span style="color:#75715e">//输入两个字符串  
</span><span style="color:#75715e"></span>  a[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">=</span>str1.length();  <span style="color:#75715e">//取得第一个字符串的长度  
</span><span style="color:#75715e"></span>  <span style="color:#66d9ef">for</span>(i<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>;i<span style="color:#f92672">&lt;</span><span style="color:#f92672">=</span>a[<span style="color:#ae81ff">0</span>];i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)  <span style="color:#75715e">//把第一个字符串转换为整数，存放在数组a中  
</span><span style="color:#75715e"></span>    a[i]<span style="color:#f92672">=</span>str1[a[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">-</span>i]<span style="color:#f92672">-</span><span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">0</span><span style="color:#e6db74">&#39;</span>;  
  b[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">=</span>str2.length();   <span style="color:#75715e">//取得第二个字符串长度  
</span><span style="color:#75715e"></span>  <span style="color:#66d9ef">for</span>(i<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>;i<span style="color:#f92672">&lt;</span><span style="color:#f92672">=</span>b[<span style="color:#ae81ff">0</span>];i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)   <span style="color:#75715e">//把第二个字符串中的每一位转换为整数，存放在数组B中  
</span><span style="color:#75715e"></span>    b[i]<span style="color:#f92672">=</span>str2[b[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">-</span>i]<span style="color:#f92672">-</span><span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">0</span><span style="color:#e6db74">&#39;</span>;  
  len<span style="color:#f92672">=</span>(a[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">&gt;</span>b[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">?</span>a[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">:</span>b[<span style="color:#ae81ff">0</span>]);   <span style="color:#75715e">//取两个字符串最大的长度  
</span><span style="color:#75715e"></span>  <span style="color:#66d9ef">for</span>(i<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>;i<span style="color:#f92672">&lt;</span><span style="color:#f92672">=</span>len;i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)   <span style="color:#75715e">//做按位加法，同时处理进位  
</span><span style="color:#75715e"></span>  {  
    a[i]<span style="color:#f92672">+</span><span style="color:#f92672">=</span>b[i];  
    a[i<span style="color:#f92672">+</span><span style="color:#ae81ff">1</span>]<span style="color:#f92672">+</span><span style="color:#f92672">=</span>a[i]<span style="color:#f92672">/</span><span style="color:#ae81ff">10</span>;  
    a[i]<span style="color:#f92672">%</span><span style="color:#f92672">=</span><span style="color:#ae81ff">10</span>;     
  }  
  len<span style="color:#f92672">+</span><span style="color:#f92672">+</span>;    <span style="color:#75715e">//下面是去掉最高位的0，然后输出。  
</span><span style="color:#75715e"></span>  <span style="color:#66d9ef">while</span>((a[len]<span style="color:#f92672">=</span><span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>)<span style="color:#f92672">&amp;</span><span style="color:#f92672">&amp;</span>(len<span style="color:#f92672">&gt;</span><span style="color:#ae81ff">1</span>)) len<span style="color:#f92672">-</span><span style="color:#f92672">-</span>;  
  <span style="color:#66d9ef">for</span>(i<span style="color:#f92672">=</span>len;i<span style="color:#f92672">&gt;</span><span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>;i<span style="color:#f92672">-</span><span style="color:#f92672">-</span>)  
    cout<span style="color:#f92672">&lt;</span><span style="color:#f92672">&lt;</span>a[i];  
  <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;   
}  
</code></pre></div><hr>
<h2 id="高精度减法">高精度减法</h2>
<blockquote>
<p>做减法时需要注意可能产生负号，要先比较两个数大小。</p>
</blockquote>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp"><span style="color:#75715e">#</span><span style="color:#75715e">include</span><span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;

<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">compare</span>(string a,string b)
{
	<span style="color:#66d9ef">if</span> (a.length() <span style="color:#f92672">&gt;</span> b.length()) <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">1</span>;
	<span style="color:#66d9ef">else</span> <span style="color:#66d9ef">if</span> (a.length() <span style="color:#f92672">&lt;</span> b.length()) <span style="color:#66d9ef">return</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>;
	<span style="color:#66d9ef">else</span>
	{
		<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> a.length(); i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
		{
			<span style="color:#66d9ef">if</span> (a[i] <span style="color:#f92672">&gt;</span> b[i]) <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">1</span>;
			<span style="color:#66d9ef">else</span> <span style="color:#66d9ef">if</span>(a[i]<span style="color:#f92672">&lt;</span>b[i]) <span style="color:#66d9ef">return</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>;
		}
	}
}

<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>()
{
	string str1, str2; <span style="color:#75715e">//str1 - str 2
</span><span style="color:#75715e"></span>	<span style="color:#66d9ef">int</span> a[<span style="color:#ae81ff">250</span>], b[<span style="color:#ae81ff">250</span>];
	memset(a, <span style="color:#ae81ff">0</span>, <span style="color:#66d9ef">sizeof</span>(a));
	memset(b, <span style="color:#ae81ff">0</span>, <span style="color:#66d9ef">sizeof</span>(b));

	<span style="color:#66d9ef">int</span> len1, len2;
	cin <span style="color:#f92672">&gt;</span><span style="color:#f92672">&gt;</span> str1 <span style="color:#f92672">&gt;</span><span style="color:#f92672">&gt;</span> str2;
	len1 <span style="color:#f92672">=</span> str1.length();
	len2 <span style="color:#f92672">=</span> str2.length();

	<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> len1; i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
	{
		a[i] <span style="color:#f92672">=</span> str1[len1 <span style="color:#f92672">-</span> i <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>] <span style="color:#f92672">-</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">0</span><span style="color:#e6db74">&#39;</span>;
	}
	<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> len2; i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
	{
		b[i] <span style="color:#f92672">=</span> str2[len2 <span style="color:#f92672">-</span> i <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>] <span style="color:#f92672">-</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">0</span><span style="color:#e6db74">&#39;</span>;
	}

	<span style="color:#66d9ef">if</span> (compare(str1, str2) <span style="color:#f92672">=</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>)
	{
		<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> len1; i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
		{
			a[i] <span style="color:#f92672">-</span><span style="color:#f92672">=</span> b[i];
			<span style="color:#66d9ef">if</span> (a[i] <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span>)
			{
				a[i <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>]<span style="color:#f92672">-</span><span style="color:#f92672">-</span>;
				a[i] <span style="color:#f92672">+</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>;
			}
		}
		<span style="color:#66d9ef">while</span> (a[len1] <span style="color:#f92672">=</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span><span style="color:#f92672">&amp;</span><span style="color:#f92672">&amp;</span>len1<span style="color:#f92672">&gt;</span><span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>) len1<span style="color:#f92672">-</span><span style="color:#f92672">-</span>;
		<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> len1; i <span style="color:#f92672">&gt;</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i<span style="color:#f92672">-</span><span style="color:#f92672">-</span>) cout <span style="color:#f92672">&lt;</span><span style="color:#f92672">&lt;</span> a[i];
		cout <span style="color:#f92672">&lt;</span><span style="color:#f92672">&lt;</span> endl;
	}
	<span style="color:#66d9ef">if</span> (compare(str1, str2) <span style="color:#f92672">=</span><span style="color:#f92672">=</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>)
	{
		<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> len2; i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
		{
			b[i] <span style="color:#f92672">-</span><span style="color:#f92672">=</span> a[i];
			<span style="color:#66d9ef">if</span> (b[i] <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span>)
			{
				b[i <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>]<span style="color:#f92672">-</span><span style="color:#f92672">-</span>;
				b[i] <span style="color:#f92672">+</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span>;
			}
		}
		<span style="color:#66d9ef">while</span> (b[len2] <span style="color:#f92672">=</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span><span style="color:#f92672">&amp;</span><span style="color:#f92672">&amp;</span>len2<span style="color:#f92672">&gt;</span><span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>) len2<span style="color:#f92672">-</span><span style="color:#f92672">-</span>;
		cout <span style="color:#f92672">&lt;</span><span style="color:#f92672">&lt;</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">-</span><span style="color:#e6db74">&#39;</span>;
		<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> len2; i <span style="color:#f92672">&gt;</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i<span style="color:#f92672">-</span><span style="color:#f92672">-</span>) cout <span style="color:#f92672">&lt;</span><span style="color:#f92672">&lt;</span> b[i];
		cout <span style="color:#f92672">&lt;</span><span style="color:#f92672">&lt;</span> endl;
	}
	<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
</code></pre></div><h2 id="高精度乘法">高精度乘法</h2>
<blockquote>
<p>需要创造一个新数组来放答案，否则乘积会溢出。</p>
</blockquote>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp"><span style="color:#75715e">#</span><span style="color:#75715e">include</span><span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;

<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>()
{
	string str1, str2;
	cin <span style="color:#f92672">&gt;</span><span style="color:#f92672">&gt;</span> str1 <span style="color:#f92672">&gt;</span><span style="color:#f92672">&gt;</span> str2;
	<span style="color:#66d9ef">int</span> a[<span style="color:#ae81ff">250</span>], b[<span style="color:#ae81ff">250</span>],c[<span style="color:#ae81ff">500</span>];
	memset(a, <span style="color:#ae81ff">0</span>, <span style="color:#66d9ef">sizeof</span>(a));
	memset(b, <span style="color:#ae81ff">0</span>, <span style="color:#66d9ef">sizeof</span>(b));
	memset(c, <span style="color:#ae81ff">0</span>, <span style="color:#66d9ef">sizeof</span>(c));
	<span style="color:#66d9ef">int</span> len1, len2;
	len1 <span style="color:#f92672">=</span> str1.length();
	len2 <span style="color:#f92672">=</span> str2.length();
	<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> len1; i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
	{
		a[i] <span style="color:#f92672">=</span> str1[len1 <span style="color:#f92672">-</span> i <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>] <span style="color:#f92672">-</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">0</span><span style="color:#e6db74">&#39;</span>;
	}
	<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> len2; i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
	{
		b[i] <span style="color:#f92672">=</span> str2[len2 <span style="color:#f92672">-</span> i <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>] <span style="color:#f92672">-</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">0</span><span style="color:#e6db74">&#39;</span>;
	}

	<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> len1; i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
	{
		<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> j <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; j <span style="color:#f92672">&lt;</span> len2; j<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
		{
			c[i <span style="color:#f92672">+</span> j] <span style="color:#f92672">+</span><span style="color:#f92672">=</span> a[i]<span style="color:#f92672">*</span>b[j];
			c[i <span style="color:#f92672">+</span> j <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>] <span style="color:#f92672">+</span><span style="color:#f92672">=</span> c[i <span style="color:#f92672">+</span> j] <span style="color:#f92672">/</span> <span style="color:#ae81ff">10</span>;
			c[i <span style="color:#f92672">+</span> j] <span style="color:#f92672">=</span> c[i <span style="color:#f92672">+</span> j] <span style="color:#f92672">%</span> <span style="color:#ae81ff">10</span>;
		}
	}
	<span style="color:#66d9ef">int</span> lenth <span style="color:#f92672">=</span> len1 <span style="color:#f92672">+</span> len2;
	<span style="color:#66d9ef">while</span> (c[lenth] <span style="color:#f92672">=</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span><span style="color:#f92672">&amp;</span><span style="color:#f92672">&amp;</span>lenth<span style="color:#f92672">&gt;</span><span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>) lenth<span style="color:#f92672">-</span><span style="color:#f92672">-</span>;
	<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> lenth; i <span style="color:#f92672">&gt;</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i<span style="color:#f92672">-</span><span style="color:#f92672">-</span>)
		cout <span style="color:#f92672">&lt;</span><span style="color:#f92672">&lt;</span> c[i];
	cout <span style="color:#f92672">&lt;</span><span style="color:#f92672">&lt;</span> endl;
	<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
</code></pre></div><h2 id="高精度除法">高精度除法</h2>
<h3 id="高精度单精度">高精度/单精度</h3>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp"><span style="color:#75715e">#</span><span style="color:#75715e">include</span><span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;

<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>()
{
	string str;
	<span style="color:#66d9ef">int</span> a[<span style="color:#ae81ff">250</span>],c[<span style="color:#ae81ff">250</span>];
	<span style="color:#66d9ef">int</span> b,lena;
	cin <span style="color:#f92672">&gt;</span><span style="color:#f92672">&gt;</span> str <span style="color:#f92672">&gt;</span><span style="color:#f92672">&gt;</span> b;
	memset(a, <span style="color:#ae81ff">0</span>, <span style="color:#66d9ef">sizeof</span>(a));
	memset(c, <span style="color:#ae81ff">0</span>, <span style="color:#66d9ef">sizeof</span>(c));
	lena <span style="color:#f92672">=</span> str.length();
	<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> lena; i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
	{
		a[i] <span style="color:#f92672">=</span> str[i] <span style="color:#f92672">-</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">0</span><span style="color:#e6db74">&#39;</span>; <span style="color:#75715e">//正序放入
</span><span style="color:#75715e"></span>	}
	<span style="color:#66d9ef">int</span> x <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
	<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> lena; i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
	{
		c[i] <span style="color:#f92672">=</span> (x <span style="color:#f92672">*</span> <span style="color:#ae81ff">10</span> <span style="color:#f92672">+</span> a[i]) <span style="color:#f92672">/</span> b;
		x <span style="color:#f92672">=</span> (x <span style="color:#f92672">*</span> <span style="color:#ae81ff">10</span> <span style="color:#f92672">+</span> a[i]) <span style="color:#f92672">%</span> b;
	}
	<span style="color:#66d9ef">int</span> lenc <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
	<span style="color:#66d9ef">while</span> (c[lenc] <span style="color:#f92672">=</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">&amp;</span><span style="color:#f92672">&amp;</span> lenc <span style="color:#f92672">&lt;</span> lena) lenc<span style="color:#f92672">+</span><span style="color:#f92672">+</span>;
	<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> lenc; i <span style="color:#f92672">&lt;</span> lena; i<span style="color:#f92672">+</span><span style="color:#f92672">+</span>)
		cout <span style="color:#f92672">&lt;</span><span style="color:#f92672">&lt;</span> c[i];
	cout <span style="color:#f92672">&lt;</span><span style="color:#f92672">&lt;</span> endl;
	<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
</code></pre></div></article>
    </section>

    <footer class="ui attached segment dream-tags">
      
          <a class="ui label">No Tags</a>
      
      <div
        class="ui label"
        style="float: right; cursor: pointer;"
        onclick="savePostAsImg()">
        <i class="save icon"></i>Save as image
      </div>
    </footer>

    

    
    
    

  </div>
  <div class="sixteen wide mobile sixteen wide tablet four wide computer column">
    <article class="dream-header">
  <section class="ui top attached center aligned segment">
    <div class="ui small circular image">
      
        <img src="/img/sleep.jpg">
      
    </div>

    
    <h1 class="ui medium header">Lindixuan&#39;s blog<div class="sub header" style="margin-top: 0.5rem;">好耶！</div>
    </h1>
    

    <div class="ui horizontal list">
      
      <a class="item" href="/tags">
        <i class="tags icon" title="All Tags"></i>
      </a>
      <a class="item" href="/categories">
        <i class="th list icon" title="All Categories"></i>
      </a>
    </div>
  </section>

  

  

  <section class="ui attached segment header-socials">
    <nav class="ui secondary menu dream-menu dream-socials">
  
  
    <div class="item">
      <a href="mailto:1228210482@qq.com">
        <i class=" mail icon" title="Email"></i>
      </a>
    </div>
  

  

  

  

  

  

  

  
</nav>

  </section>

  <section class="ui bottom attached center aligned segment">
    
      <p>© 2020 - 2021 Hugo Theme Dream</p>
    

    <p>Powered by <a href="https://gohugo.io/" target="_blank">Hugo</a> with theme <a href="https://github.com/g1eny0ung/hugo-theme-dream" target="_blank">Dream</a>.</p>

    
  </section>
</article>

  </div>
</div>

          </div>
        </section>
        <section class="back">
          <div class="dream-max-width">
            <div class="ui centered relaxed grid dream-grid dream-back">
  
  
  

  <section class="sixteen wide mobile eight wide tablet four wide computer column dream-column">
    <article>
      <div class="ui top attached segment">
        <h3 class="ui header">Social Links</h3>
      </div>
      <div class="ui bottom attached segment">
        <nav class="ui secondary menu dream-menu dream-socials">
  
  
    <div class="item">
      <a href="mailto:1228210482@qq.com">
        <i class="large mail icon" title="Email"></i>
      </a>
    </div>
  

  

  

  

  

  

  

  
</nav>

      </div>
    </article>
  </section>

  <section class="sixteen wide mobile eight wide tablet four wide computer column dream-column">
    
  </section>

  
    
  
</div>

          </div>
        </section>
      </div>
    </div>

    <script>
  window.darkNav =  true 
</script>
<script src="/js/jquery.min.js"></script>
<script src="/js/semantic.min.js"></script>
<script src="/js/jquery.overlayScrollbars.min.js"></script>
<script src="/js/header.js"></script>
<script src="/js/main.js"></script>
<script src="/js/theme.js"></script>

    
<script src="/js/html2canvas.min.js"></script>
<script src="/js/post.js"></script>


  <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/highlight.min.js"></script>

  
    
      <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/languages/ocaml.min.js"></script>
     
  

  <script>
  hljs.initHighlightingOnLoad()
  setHighlightTheme()

  function setHighlightTheme() {
    var isDark = localStore.getItem('hugo-theme-dream-is-dark')
    var lightTheme = "gruvbox-light"
    var darkTheme = "gruvbox-dark"
    var theme = isDark ? darkTheme : lightTheme

    $('link[data-highlight]').attr('href', 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/styles/' + theme + '.min.css')
    $('pre').css('background', isDark ? '#333' : '')
  }
</script>





    
      <div class="ui inverted segment" id="dream-search">
  <div class="ui search">
    <div class="ui transparent input">
      <input class="prompt" type="text" placeholder="Search" />
    </div>
    <div class="results"></div>
  </div>
</div>
<script>
  $(document).ready(function () {
    $.getJSON('https:\/\/lindixuan.gitee.io/index.json', function (data) {
      $('.ui.search').search({
        source: data,
        searchFields: ['title'],
        showNoResults: true,
      })
    })
  })
</script>
<script src="/js/search.js"></script>

    

    
  </body>
</html>
